$(function(){
	var chargeMoney = localStorage.chargeMoney;
	var orderId = localStorage.orderId;
	var num = 0;
	var test = 0;
	$("#money").text(chargeMoney);

	$('.rec-btn button').click(function(){
		var obj = JSON.parse(localStorage.sub_canshu);
		$.ajax({
			type:'post',
			url: url() + '/quiz/fetch2',
			data:{
				catId:obj.id,
				quizUuid:obj.uuid,
				betMoney:obj.money,
				couponId:obj.coup
			},
			dataType:'json',
			success:function(rut,sta,xhr){
				var sessionstatus = xhr.getResponseHeader('redirectStatus');
				
				if(sessionstatus == '302'){
					window.location.href = url() + '/wxuser/goCompleteInfo';
					return false;
				};
				var rut_obj = JSON.parse(rut.result);
				if(rut.code == 0 && rut_obj.status == 0){
					/*题目存储subject*/
					localStorage.subject = rut.result;
					/*当前题题目*/
					localStorage.now_title = rut_obj.object.title;
					/*分享地址参数id*/
					localStorage.quizInstanceId = rut_obj.object.quizInstanceId;
					localStorage.user_balance = 0;
					window.location.href = url() + '/htm/subject.html'
				}else{
					alert(rut_obj.message)
				}
			},
			error:function(){

			}
		})
	});
	var time = setInterval(function(){
		$.ajax({
			type:'post',
			url: url() + '/userCharge/getOrderStatus',
			data:{
				orderId:orderId
			},
			dataType:'json',
			success:function(rel,sta,xhr){
				var sessionstatus = xhr.getResponseHeader('redirectStatus');
				
				if(sessionstatus == '302'){
					window.location.href = url() + '/wxuser/goCompleteInfo';
					return false;
				};
				num ++ ;
				console.log(rel)
				var rel_obj = JSON.parse(rel.result);
				if(rel.code == 0 && rel_obj.status == 0){
					if( num <= 10){
						if(rel_obj.object == 1){
							clearInterval(time);
							$('#loadingToast').hide();
							
						}else if(rel_obj.object == 2){
							if(test == 0){
								if(confirm('继续申请')){
									num = 0
								}else{
									clearInterval(time);
									alert('您的充值未到账，请去微信查看交易金额是否返还或联系微信客服帮您查询,您本次订单号：'+orderId);
									window.location.href = url() + '/htm/index.html';
								}
							}else{
								clearInterval(time);
								alert('您的充值未到账，请去微信查看交易金额是否返还或联系微信客服帮您查询,您本次订单号：'+orderId);
								window.location.href = url() + '/htm/index.html';
							}
						}
					}else{
						if(test == 0){
							if(confirm('继续申请')){
								num = 0
							}else{
								clearInterval(time)
								alert('您的充值产生异常，请联系客服帮您查询 010-85655955');
								window.location.href = url() + '/htm/index.html'
							}
						}else{
							clearInterval(time)
							alert('您的充值产生异常，请联系客服帮您查询 010-85655955');
							window.location.href = url() + '/htm/index.html'
						}
						
					}
							
				}else{
					alert(rel_obj.message)
				}
			},
			error:function(){

			}

		})
	},3000)
	
})